#include("../../comm/ListHead.html")
<style>
</style>
<div class="layui-fluid layui-anim layui-anim-scale">
    <div class="layui-row layui-col-space5">
        <div class="layui-col-md2 height-auto width-14">
            <div class="layui-card height-scoll">
                <div id="tree_1" class="demo-tree demo-tree-box"></div>
            </div>
        </div>
        <div class="layui-col-md10 width-86">
            <div class="layui-card">
                <div class="card-search SearchTable">
                    <p style="float:right">
                        <input type="hidden" id="[treekey]" name="[treekey]" value="#(form.data.def_id??)"/>
                        <input type="hidden" id="titles" name="titles" value="#(form.data.def_title??)"/>
                        [searchdiv]
                        <button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="DoSearch">
                            搜索
                        </button>
                        [searchmorediv]
                    </p>
                    当前位置 > <span id="navtitle" class="color_green">[#(form.data.def_id??)]#(form.data.def_title??)</span>
                </div>
                <div class="layui-card-body">
                    <table class="layui-hide" id="table_1" lay-filter="table_1"></table>

                    <script type="text/html" id="table_1_bar_title">
                        <div class="layui-btn-container" style="float:left">
                            <button class="layui-btn layui-btn-sm btn-add" lay-event="Add[model]">
                                <i class="layui-icon">&#xe608;</i> 添加[pagename]
                            </button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-edit" lay-event="Edit[model]">修改</button>
                            <button class="layui-btn layui-btn-sm layui-btn-disabled" permission-one="btn-del" lay-event="Del[model]">删除</button>
                        </div>
                        <div id="bar_desc"></div>
                    </script>
                    [searchmore]
                    [templet]
                    [tabletoolbar]
                </div>
            </div>
        </div>
    </div>
</div>
<script language="JavaScript">

    layui.use(['myTable', 'table', 'form', 'myTree', 'myTool','drawer'], function () {
        admin = layui.admin, myTool = layui.myTool, form = layui.form, myTree = layui.myTree;
        var $ = layui.$;
        treedata = #(form.data.tree);

        /**
         * 树渲染
         */
        myTree.render({
            data: treedata, init:$("#[treekey]").val()
            , click: function (obj) {
                var data = obj.data;
                if (data.turn) {
                    $("#[treekey]").val(data.id);
                    $("#navtitle").html("[" + data.id + "]" + data.title);
                    $("#titles").val(data.title);
                    tableindex.reload({where: {[treekey]:data.id},page: {curr: 1}});
                }
            }
        });

    [searchmorejs]
    /**
     * 表格
     */
    tableindex = layui.myTable.render({
        elem: '#table_1', url: '[model]ListDataApi'
        ,title: '列表'
        , where: {[treekey]:$("#[treekey]").val()}
        ,cols: [[
               {type: 'checkbox',width:36}
               [columns]
           ]]
            , page:true, limit:10
            , serviceSort: true, initSort: {field: '[modelkey]', type: 'desc'}
            , editField:{url: 'Modify[model]FieldApi', key:'[modelkey]'}
            , done: function (res, curr, count) {
               $("#bar_desc").html("");
            }
    });

    /**
     * 按钮事件
     */
    layui.util.event("lay-event", {
        DoSearch: function () {
            tableindex.config.where={[treekey]:$("#[treekey]").val(),[searchjs]};
            tableindex.reload({where:tableindex.config.where, page: {curr: 1}});
        }
        ,DoSearchMore: function () {
        layui.form.render();
        drawer1.open();
        }
    });

    /**
     * 工具栏事件
     */
    layui.table.on('toolbar(table_1)', function (obj) {
        myTool.toolbar(this, obj, {
            Add[model]:function () {
            index = top.layer.open({
                type: 2, offset: '60px', area: ['700px', '550px'], title: ['添加[pagename]', 'font-size:15px;'],
                content: ["[path]/Add[model]?[treekey]="+$("#[treekey]").val(), 'no'],
                end: function () {
                    tableindex.reload({});
                }
            });
        }
        ,Edit[model]:function () {
            myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                index = top.layer.open({
                    type: 2, offset: '60px', area: ['700px', '550px'], title: ['修改[pagename][' + data[0].[modelkey] + ']', 'font-size:15px;'],
                    content: ["[path]/Edit[model]?[modelkey]=" + data[0].[modelkey], 'no'],
                    end: function () {
                        tableindex.reload({});
                    }
                });
            });
        }
        ,Del[model]:function () {
            myTool.doSingleSelect(layui.myTable.checkStatus('table_1'), {}, function (data, keys) {
                index = layer.confirm('你是否确认删除[pagename]【' + data[0].[modelkey] + '】', {icon: 3, title: '提示', offset: '100px'}, function (index2) {
                    myTool.postMsg("Del[model]Api", {[modelkey]:data[0].[modelkey]
                }, function () {
                    layer.close(index2);
                    tableindex.reload();
                });
            });
        });
    }
    });
    });

    [tabletooljs]

    form.on('checkbox(ChangeTag)', function (obj) {
        myTool.postMsg("Change[model]TagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
            layer.tips(result.msg, obj.othis);
        });
    });
    form.on('switch(ChangeTag)', function (obj) {
        myTool.postMsg("Change[model]TagApi", {key: this.value, field: $(obj.elem).attr("field"), msg: $(obj.elem).attr("msg")}, function (result) {
            layer.tips(result.msg, obj.othis);
        });
    });
    });
</script>
#include("../../comm/Foot.html")